PATHMac OS 8 and 9 Developer Documentation > Human Interface Toolbox > Appearance Manager >

Programming With the Appearance Manager


Making an Object Drawn With QuickDraw Theme-Compliant

Listing 3-3 shows a sample function called MyEditTextFrameDraw , which, depending upon the presence of the Appearance Manager, branches between two functions, each of which draws a frame for an editable text field. Prior to drawing, the MyEditTextFrameDraw function calls the MyIsAppearancePresent function, described in Becoming a Client of the Appearance Manager , to determine whether the Appearance Manager is present.

If the Appearance Manager is not present, MyEditTextFrameDraw calls the non-theme-compliant function MyClassicEditTextFrameDraw . MyClassicEditTextFrameDraw draws a frame by setting the dimensions of the rectangle and its color with calls to QuickDraw. However, an editable text frame drawn in this manner maintains a "fixed" look in any appearance and cannot adapt to theme switches.

If the Appearance Manager is present, however, MyEditTextFrameDraw calls the MyAppearanceSavvyEditTextFrameDraw function. MyAppearanceSavvyEditTextFrameDraw then passes the appropriate Appearance Manager constant for the drawing state ( kThemeStateActive or kThemeStateInactive ) to the function DrawThemeEditTextFrame . DrawThemeEditTextFrame draws the frame appropriately for the activity state and the current theme. And, when a theme switch occurs, the frame automatically takes on a look consistent with the current theme.

Listing 3-3   Moving from QuickDraw to the Appearance Manager

static pascal OSStatus MyClassicEditTextFrameDraw (
                                                const Rect *bounds,
                                                Boolean active)
{
    Rect frame = *bounds;
    InsetRect (&frame,-1,-1);
    // We're pre-Appearance Mgr here, so always draw in black...
    PenNormal ( );
    // unless the editable text field is inactive; in that case, draw in gray
    if (!active) PenPat (&(qd.gray));
    FrameRect (&frame);
    return noErr;
}

static pascal OSStatus MyAppearanceSavvyEditTextFrameDraw (
                                                const Rect *bounds,
                                                Boolean active)
{
    DrawThemeEditTextFrame (bounds,
        active ? kThemeStateActive : kThemeStateInactive);
    return noErr;
}

static pascal OSStatus MyEditTextFrameDraw (const Rect *bounds, Boolean active)
{
    OSStatus err = noErr;

    Boolean haveAppearance;

    if (!(err = MyIsAppearancePresent (&haveAppearance)))
    {
        if (haveAppearance)
            err = MyAppearanceSavvyEditTextFrameDraw (bounds, active);
        else
            err = MyClassicEditTextFrameDraw (bounds, active);
    }

    return err;
}

© 1999 Apple Computer, Inc. – (Last Updated 29 April 99)